﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.zoo.ui {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import __AS3__.vec.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import org.aswing.event.*;
    import org.aswing.util.*;
    import Modules.zoo.events.*;
    import Display.aswingui.*;
    import Modules.zoo.*;
    import Mechanics.Transactions.*;

    public class ZooDialogView extends GenericDialogView {

        public static const WINDOW_WIDTH:int = 749;
        public static const WINDOW_HEIGHT:int = 545;
        public static const BACKDROP_PANE_HEIGHT:int = 290;
        public static const TAB_WIDTH:int = 50;
        public static const TAB_HEIGHT:int = 50;
        public static const TAB_CAP_FONT_SIZE:int = 22;
        public static const TAB_FONT_SIZE:int = 16;

        private static var m_currentInstance:ZooDialogView;

        private var m_enclosureData:Array;
        private var m_currentSelectedTabIndex:int;
        private var m_currentSelectedEnclosure:ZooEnclosure;
        private var m_currSlotMechanic:ISlotMechanic;
        private var m_currStorageMechanic:IStorageMechanic;
        private var m_selectedEnclosureDefinition:Item;
        private var m_tooltipData:Dictionary;
        protected var m_tabs:Vector.<JPanel>;
        protected var m_closedEnabled:Boolean = true;
        private var m_currentBackdrop:EnclosureBackdrop;
        private var m_mainContentPanel:JPanel;
        private var m_backdropAssetPane:AssetPane;
        protected var m_bottomPanel:JPanel;
        protected var m_marketPanel:JPanel;
        protected var m_zooMarket:ZooScrollingList;
        protected var m_seeZooButton:CustomButton;
        protected var m_buyDonationsButton:CustomButton;
        private var m_spawner:MechanicMapResource;
        protected var m_toolTip:ZooToolTip;
        protected var m_tabToolTip:ItemCategoryToolTip;
        public var lastDefaultKey:String;
        protected var m_buttonPanel:JPanel;
        protected var m_enclosureNamesArray:Array;

        public function ZooDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:ZooEnclosure=null, _arg7:String="", _arg8:int=0, _arg9:String="", _arg10:Function=null, _arg11:String=""){
            m_currentInstance = this;
            this.m_tooltipData = new Dictionary();
            this.m_currentSelectedEnclosure = _arg6;
            this.m_spawner = _arg1["spawner"];
            this.m_enclosureNamesArray = [ZLoc.t("Dialogs", "ZooDialog_savannah"), ZLoc.t("Dialogs", "ZooDialog_jungle")];
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg7, _arg8, _arg9, _arg10, _arg11);
            this.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS));
        }
        public static function get currentInstance():ZooDialogView{
            return (m_currentInstance);
        }

        public function get currSlotMechanic():ISlotMechanic{
            return (this.m_currSlotMechanic);
        }
        public function get currStorageMechanic():IStorageMechanic{
            return (this.m_currStorageMechanic);
        }
        public function get currZooEnclosure():ZooEnclosure{
            return (this.m_currentSelectedEnclosure);
        }
        override protected function init():void{
            this.m_enclosureData = Global.gameSettings.getItemsByType("zooEnclosure");
            this.m_currSlotMechanic = (MechanicManager.getInstance().getMechanicInstance(this.m_currentSelectedEnclosure, ZooManager.MECHANIC_SLOTS, MechanicManager.ALL) as ISlotMechanic);
            this.m_currStorageMechanic = (MechanicManager.getInstance().getMechanicInstance(this.m_currentSelectedEnclosure, ZooManager.MECHANIC_STORAGE, MechanicManager.ALL) as IStorageMechanic);
            this.m_currSlotMechanic.sendTransactions = false;
            this.m_currStorageMechanic.sendTransactions = false;
            this.m_tabs = new Vector.<JPanel>();
            super.init();
        }
        override protected function createHeaderPanel():JPanel{
            var _local1:JPanel = new JPanel(new BorderLayout());
            var _local2:JPanel = createCloseButtonPanel();
            ASwingHelper.prepare(_local2);
            _local1.append(ASwingHelper.horizontalStrut(_local2.getWidth()), BorderLayout.WEST);
            _local1.append(_local2, BorderLayout.EAST);
            return (_local1);
        }
        override protected function makeBackground():void{
            var _local1:MarginBackground;
            if (m_bgAsset){
                _local1 = new MarginBackground(m_bgAsset, new Insets(0, 0, 20, 0));
                this.setBackgroundDecorator(_local1);
            };
        }
        override protected function makeCenterPanel():void{
            var _local4:int;
            setBackgroundDecorator(new AssetBackground(m_bgAsset));
            setPreferredSize(new IntDimension(WINDOW_WIDTH, WINDOW_HEIGHT));
            this.m_backdropAssetPane = new AssetPane();
            this.m_backdropAssetPane.setPreferredSize(new IntDimension(WINDOW_WIDTH, BACKDROP_PANE_HEIGHT));
            this.m_mainContentPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            this.m_mainContentPanel.setPreferredSize(new IntDimension(WINDOW_WIDTH, BACKDROP_PANE_HEIGHT));
            this.m_mainContentPanel.append(this.m_backdropAssetPane);
            this.m_marketPanel = ASwingHelper.makeFlowJPanel(SoftBoxLayout.LEFT);
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(1, -3);
            _local1.appendAll(this.makeTabsPanel(), this.m_marketPanel);
            this.m_bottomPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            this.m_bottomPanel.appendAll(_local1, ASwingHelper.horizontalStrut(10));
            this.m_toolTip = new ZooToolTip();
            this.m_toolTip.visible = false;
            this.m_tabToolTip = new ItemCategoryToolTip();
            this.m_tabToolTip.visible = false;
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local2.setPreferredHeight(BACKDROP_PANE_HEIGHT);
            _local2.appendAll(this.m_mainContentPanel, ASwingHelper.verticalStrut(-(BACKDROP_PANE_HEIGHT)), this.createHeaderPanel());
            this.m_buttonPanel = this.makeButtonPanel();
            appendAll(_local2, this.m_bottomPanel, ASwingHelper.verticalStrut(-15), this.m_buttonPanel);
            addChild(this.m_toolTip);
            addChild(this.m_tabToolTip);
            var _local3:int;
            if (this.m_spawner){
                _local4 = 0;
                while (_local4 < this.m_enclosureData.length) {
                    if ((this.m_enclosureData[_local4] as Item).name == this.m_spawner.getItem().name){
                        _local3 = _local4;
                        break;
                    };
                    _local4++;
                };
            };
            this.setSelectedTab(_local3);
        }
        private function makeAndUpdateMarketPanel():void{
            var _local2:Item;
            var _local3:MechanicConfigData;
            var _local4:String;
            var _local5:int;
            var _local6:int;
            this.m_marketPanel.removeAll();
            var _local1:Array = [];
            if (this.m_currStorageMechanic){
                _local1 = Global.gameSettings.getItemsByKeywords(this.m_currStorageMechanic.restrictedKeywords);
            } else {
                _local2 = (this.m_enclosureData[this.m_currentSelectedTabIndex] as Item);
                _local3 = _local2.getGameEventMechanicConfig(MechanicManager.ALL, "storage");
                if (_local3){
                    _local4 = (_local3.params["restrictByKeywords"] as String);
                    _local1 = Global.gameSettings.getItemsByKeywords(_local4.split(","));
                };
            };
            if (this.m_zooMarket == null){
                this.m_zooMarket = new ZooScrollingList(_local1, ZooCellFactory, 0, 6, 1);
                this.m_zooMarket.addEventListener(ZooDialogEvent.ADD_ANIMAL_TO_DISPLAY, this.onAnimalCellPlaceButtonClicked, false, 0, true);
                this.m_zooMarket.addEventListener(ZooDialogEvent.BUY_NEW_ANIMAL, this.onAnimalBought, false, 0, true);
            } else {
                _local5 = Math.min(6, _local1.length);
                this.m_zooMarket.model.removeRange(0, (this.m_zooMarket.model.getSize() - 1));
                _local6 = 0;
                while (_local6 < _local5) {
                    this.m_zooMarket.model.append(_local1[_local6]);
                    _local6++;
                };
            };
            ASwingHelper.setEasyBorder(this.m_zooMarket, 0, 0, 10, 0);
            this.m_marketPanel.append(this.m_zooMarket);
            ASwingHelper.prepare(this);
        }
        private function makeTabsPanel():JPanel{
            var _local5:Item;
            var _local6:ImageTab;
            var _local7:Boolean;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 4);
            var _local2:int;
            while (_local2 < this.m_enclosureData.length) {
                _local5 = (this.m_enclosureData[_local2] as Item);
                _local6 = new ImageTab(_local5.getImageByName("tabs_off"), _local5.getImageByName("tabs_on"));
                _local6.addEventListener(MouseEvent.MOUSE_UP, this.onTabClicked, false, 0, true);
                Global.ui.addEventListener(ZooDialogEvent.UNLOCK_ENCLOSURE, this.onUnlockEnclosure);
                this.addTooltipTarget(_local6, ZLoc.t("Dialogs", ("ZooDialog_tabTooltip_" + _local5.name)));
                _local7 = BuyLogic.isLocked(_local5);
                _local6.setLocked(_local7);
                _local1.append(_local6);
                this.m_tabs.push(_local6);
                _local2++;
            };
            var _local3:ImageTab = new ImageTab();
            var _local4:DisplayObject = (new (ZooDialog.assetDict["tab_unselected"])() as DisplayObject);
            _local4.width = TAB_WIDTH;
            _local4.height = TAB_HEIGHT;
            _local3.setPreferredSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
            _local3.setBackgroundDecorator(new AssetBackground(_local4));
            this.addTooltipTarget(_local3, ZLoc.t("Dialogs", "ZooDialog_comingSoon"));
            _local1.append(_local3);
            this.m_tabs.push(_local3);
            ASwingHelper.setEasyBorder(_local1, 0, 21, 0, 8);
            return (_local1);
        }
        private function makeButtonPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_seeZooButton = new CustomButton(ZLoc.t("Dialogs", "ZooDialog_seeMyZoo"), null, "GreenButtonUI");
            this.m_seeZooButton.addActionListener(this.onSeeMyZoo);
            _local1.append(this.m_seeZooButton);
            _local1.append(ASwingHelper.horizontalStrut(10));
            this.makeBuyDonationsButton();
            _local1.append(this.m_buyDonationsButton);
            return (_local1);
        }
        protected function makeBuyDonationsButton():void{
            var icon:* = null;
            var cashValue:* = 0;
            var inventoryLimit:* = 0;
            var data:* = null;
            var item:* = null;
            var listener:* = null;
            if (this.m_currentSelectedEnclosure != null){
                icon = new AssetIcon(new (ZooDialog.assetDict["icon_cash"])());
                cashValue = Global.gameSettings.getInt(("ZooDonationNPCPrice_" + this.m_currentSelectedEnclosure.getItemName()), 20);
                inventoryLimit = 0;
                data = Global.gameSettings.getItemsByKeywords(this.m_currStorageMechanic.restrictedKeywords);
                for each (item in data) {
                    inventoryLimit = (inventoryLimit + item.inventoryLimit);
                };
                this.m_buyDonationsButton = new CustomButton(ZLoc.t("Dialogs", "ZooDialog_buyDonations", {price:cashValue}), icon, "CashButtonUI");
                if (this.m_currentSelectedEnclosure.getAnimals() >= inventoryLimit){
                    this.m_buyDonationsButton.setEnabled(false);
                };
                listener = function ():void{
                    var _local1:String;
                    TransactionManager.sendAllTransactions(true);
                    if (Global.player.cash >= cashValue){
                        _local1 = ZLoc.t("Dialogs", "ZooDialog_buyDonationsConfirm", {
                            price:cashValue,
                            enclosure:m_currentSelectedEnclosure.getItemFriendlyName()
                        });
                        UI.displayMessage(_local1, GenericPopup.TYPE_YESNO, onBuyDonation, "ZooDialog_buyDonationsConfirm", true);
                    } else {
                        UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
                    };
                };
                this.m_buyDonationsButton.addActionListener(listener);
            } else {
                if (this.m_buyDonationsButton != null){
                    this.m_buyDonationsButton.setEnabled(false);
                };
            };
        }
        public function addTooltipTarget(_arg1:DisplayObject, _arg2:String):void{
            this.m_tooltipData[_arg1] = _arg2;
            _arg1.addEventListener(MouseEvent.MOUSE_OVER, this.onTooltipTargetMouseOver, false, 0, true);
            _arg1.addEventListener(MouseEvent.MOUSE_OUT, this.onTooltipTargetMouseOut, false, 0, true);
        }
        public function removeTooltipTarget(_arg1:DisplayObject):void{
            _arg1.removeEventListener(MouseEvent.MOUSE_OVER, this.onTooltipTargetMouseOver);
            _arg1.removeEventListener(MouseEvent.MOUSE_OUT, this.onTooltipTargetMouseOut);
            delete this.m_tooltipData[_arg1];
        }
        public function setSelectedTab(_arg1:int, _arg2:Boolean=false):void{
            var _local5:DisplayObject;
            var _local6:int;
            var _local7:String;
            var _local3:uint;
            while (_local3 < this.m_tabs.length) {
                _local5 = (((_local3 == _arg1)) ? new (ZooDialog.assetDict["tab_selected"])() : new (ZooDialog.assetDict["tab_unselected"])() as DisplayObject);
                _local5.width = TAB_WIDTH;
                _local5.height = TAB_HEIGHT;
                this.m_tabs[_local3].setPreferredSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                this.m_tabs[_local3].setBackgroundDecorator(new AssetBackground(_local5));
                _local3++;
            };
            this.m_selectedEnclosureDefinition = (this.m_enclosureData[_arg1] as Item);
            if (this.m_currentBackdrop){
                this.m_currentBackdrop.removeEventListener(ZooDialogEvent.DISPLAY_UPDATE, this.onBackdropDisplayUpdate);
                this.m_currentBackdrop.removeEventListener(ZooDialogEvent.REMOVE_ANIMAL_FROM_DISPLAY, this.onBackdropRemoveAnimalFromDisplay);
                this.m_currentBackdrop.removeEventListener(Event.CLOSE, this.onBackdropClose);
            };
            this.m_currentBackdrop = new EnclosureBackdrop(this.m_selectedEnclosureDefinition.name);
            this.m_currentBackdrop.addEventListener(ZooDialogEvent.DISPLAY_UPDATE, this.onBackdropDisplayUpdate);
            this.m_currentBackdrop.addEventListener(ZooDialogEvent.REMOVE_ANIMAL_FROM_DISPLAY, this.onBackdropRemoveAnimalFromDisplay);
            this.m_currentBackdrop.addEventListener(Event.CLOSE, this.onBackdropClose);
            this.m_backdropAssetPane.setAsset(this.m_currentBackdrop);
            this.m_currentSelectedEnclosure = null;
            this.m_currSlotMechanic = null;
            this.m_currStorageMechanic = null;
            var _local4:Array = Global.world.getObjectsByNames([this.m_selectedEnclosureDefinition.name]);
            if (_local4.length > 0){
                this.m_currentSelectedEnclosure = (_local4[0] as ZooEnclosure);
                this.m_currSlotMechanic = (MechanicManager.getInstance().getMechanicInstance(this.m_currentSelectedEnclosure, ZooManager.MECHANIC_SLOTS, MechanicManager.ALL) as ISlotMechanic);
                this.m_currStorageMechanic = (MechanicManager.getInstance().getMechanicInstance(this.m_currentSelectedEnclosure, ZooManager.MECHANIC_STORAGE, MechanicManager.ALL) as IStorageMechanic);
                this.m_currSlotMechanic.sendTransactions = false;
                this.m_currStorageMechanic.sendTransactions = false;
                _local6 = 0;
                while (_local6 < this.m_currSlotMechanic.numSlots) {
                    _local7 = this.m_currSlotMechanic.getSlot(_local6);
                    if (_local7){
                        this.m_currentBackdrop.addAnimalToSlot(_local7, _local6);
                    };
                    _local6++;
                };
            };
            remove(this.m_buttonPanel);
            this.m_buttonPanel = null;
            this.m_buttonPanel = this.makeButtonPanel();
            append(this.m_buttonPanel);
            this.m_seeZooButton.setEnabled(!((this.m_currentSelectedEnclosure == null)));
            this.updateDefaultMessage();
            this.m_currentSelectedTabIndex = _arg1;
            this.makeAndUpdateMarketPanel();
            ASwingHelper.prepare(this);
        }
        public function addAnimalToDisplay(_arg1:String):Boolean{
            var _local3:TMechanicDataTransfer;
            var _local2:int = this.currSlotMechanic.fillNextSlot(_arg1);
            if (_local2 == -1){
                UI.displayMessage(ZLoc.t("Dialogs", "ZooFull_message"), 0, null, "", true);
                return (false);
            };
            this.m_currStorageMechanic.remove(_arg1, 1);
            this.m_currentBackdrop.addAnimalToSlot(_arg1, _local2);
            _local3 = new TMechanicDataTransfer(this.m_currentSelectedEnclosure);
            _local3.addDataTransfer(ZooManager.MECHANIC_STORAGE, ZooManager.MECHANIC_SLOTS, _arg1, {slot:_local2});
            GameTransactionManager.addTransaction(_local3);
            if (!Global.player.getSeenFlag("hasPlacedAnimalsInDisplay")){
                Global.player.setSeenFlag("hasPlacedAnimalsInDisplay");
            };
            this.updateDefaultMessage();
            return (true);
        }
        private function updateDefaultMessage():void{
            var _local1:String;
            var _local2:String;
            var _local3:int;
            var _local4:ZooEnclosure;
            var _local5:String;
            var _local6:int;
            var _local7:String;
            var _local8:Boolean;
            var _local9:Boolean;
            var _local10:Boolean;
            var _local11:Array;
            var _local12:ConstructionSite;
            if (((this.m_currentBackdrop) && (this.m_selectedEnclosureDefinition))){
                _local1 = "";
                _local2 = null;
                _local3 = 0;
                _local4 = null;
                if (this.m_currentSelectedEnclosure){
                    if (!Global.player.getSeenFlag("hasPlacedAnimalsInDisplay")){
                        _local1 = ZLoc.t("Dialogs", "ZooDialog_firstAnimalPlace");
                    } else {
                        _local5 = ((("ZooDialog_defaultMsg_" + this.m_selectedEnclosureDefinition.name) + "_") + Math.floor((Math.random() * 2.99)));
                        this.lastDefaultKey = _local5;
                        _local6 = this.m_currentSelectedEnclosure.getPayout();
                        _local1 = ZLoc.t("Dialogs", _local5, {percent:_local6});
                        if (Math.random() < 0.3){
                            _local7 = this.m_selectedEnclosureDefinition.unlocksItem;
                            if (_local7){
                                _local8 = BuyLogic.isLocked(Global.gameSettings.getItemByName(_local7));
                                this.lastDefaultKey = ((("ZooDialog_defaultMsg_" + this.m_selectedEnclosureDefinition.name) + "_") + "unlock");
                                _local1 = ZLoc.t("Dialogs", ((("ZooDialog_defaultMsg_" + this.m_selectedEnclosureDefinition.name) + "_") + "unlock"));
                            };
                        };
                    };
                    _local4 = this.m_currentSelectedEnclosure;
                } else {
                    _local9 = (Global.player.inventory.getItemCountByName(this.m_selectedEnclosureDefinition.name) > 0);
                    _local10 = false;
                    _local11 = Global.world.getObjectsByClass(ConstructionSite);
                    for each (_local12 in _local11) {
                        if (_local12.targetName == this.m_selectedEnclosureDefinition.name){
                            _local10 = true;
                            break;
                        };
                    };
                    if (_local9){
                        _local1 = ZLoc.t("Dialogs", ("ZooDialog_placeMessage_" + this.m_selectedEnclosureDefinition.name));
                        _local2 = this.m_selectedEnclosureDefinition.name;
                    } else {
                        if (_local10){
                            _local1 = ZLoc.t("Dialogs", ("ZooDialog_underConstruction_" + this.m_selectedEnclosureDefinition.name));
                        } else {
                            _local1 = ZLoc.t("Dialogs", ("ZooDialog_locked_" + this.m_selectedEnclosureDefinition.name));
                        };
                    };
                };
                this.m_currentBackdrop.speechBubble.setDefaultMessage(_local1, _local2, _local4);
            };
        }
        private function onAnimalCellPlaceButtonClicked(_arg1:ZooDialogEvent):void{
            var _local3:ZooCell;
            var _local2:Boolean = this.addAnimalToDisplay(_arg1.animalItemName);
            if (_local2){
                _local3 = (_arg1.target as ZooCell);
                _local3.changeCounter((_local3.count - 1));
            };
        }
        private function onBackdropClose(_arg1:Event):void{
            this.close();
        }
        private function onAnimalBought(_arg1:ZooDialogEvent):void{
            var _local4:ZooCell;
            StatsManager.sample(100, "Zoo", "onAnimalBought", this.lastDefaultKey);
            var _local2:Item = Global.gameSettings.getItemByName(_arg1.animalItemName);
            var _local3:int = this.m_currentSelectedEnclosure.getNumSpecificAnimal(_arg1.animalItemName);
            if (_local3 < _local2.inventoryLimit){
                this.m_currStorageMechanic.sendTransactions = true;
                this.m_currStorageMechanic.purchase(_arg1.animalItemName, 1, ("zoo|adopted_animal|" + _arg1.animalItemName));
                this.m_currStorageMechanic.sendTransactions = false;
                _local4 = (_arg1.target as ZooCell);
                (_arg1.target as ZooCell).changeCounter((_local4.count + 1));
                _local4.changeChrome();
                if (this.m_currentSelectedEnclosure.readyToUnlock()){
                    MechanicManager.getInstance().handleAction((this.m_currentSelectedEnclosure as IMechanicUser), "GMPlay");
                };
                this.updateDefaultMessage();
            };
            remove(this.m_buttonPanel);
            this.m_buttonPanel = null;
            this.m_buttonPanel = this.makeButtonPanel();
            append(this.m_buttonPanel);
        }
        public function onAnimalRolled(_arg1:Object):void{
            this.m_closedEnabled = true;
            this.m_currStorageMechanic.sendTransactions = false;
            this.m_currStorageMechanic.add(_arg1.data, 1);
            var _local2:Dictionary = new Dictionary();
            _local2["-1"] = _arg1.data;
            this.m_currentSelectedEnclosure.setDataForMechanic("giftSenders", _local2);
            this.close();
            MechanicManager.getInstance().handleAction(this.m_currentSelectedEnclosure, "GMPlay");
        }
        private function onSeeMyZoo(_arg1:AWEvent):void{
            if (this.m_currentSelectedEnclosure){
                Global.world.centerOnObject(this.m_currentSelectedEnclosure);
            };
            this.close();
        }
        private function onBuyDonation(_arg1:GenericPopupEvent):void{
            var _local2:int;
            if (_arg1.button == GenericPopup.ACCEPT){
                if (this.m_currentSelectedEnclosure){
                    _local2 = Global.gameSettings.getInt(("ZooDonationNPCPrice_" + this.m_currentSelectedEnclosure.getItemName()), 20);
                    Global.player.cash = (Global.player.cash - _local2);
                    GameTransactionManager.addTransaction(new TPurchaseRandomZooAnimal(this.m_currentSelectedEnclosure, this), true, true);
                };
                this.m_buyDonationsButton.setEnabled(false);
                this.m_closedEnabled = false;
            };
        }
        protected function onTabClicked(_arg1:MouseEvent):void{
            var _local2:int;
            if (this.m_closedEnabled){
                _local2 = 0;
                while (_local2 < this.m_tabs.length) {
                    if (this.m_tabs[_local2] == _arg1.currentTarget){
                        this.setSelectedTab(_local2, true);
                        break;
                    };
                    _local2++;
                };
            };
        }
        override public function close():void{
            if (this.m_closedEnabled){
                super.close();
            };
        }
        private function onBackdropDisplayUpdate(_arg1:ZooDialogEvent):void{
            this.m_backdropAssetPane.unloadAsset();
            this.m_backdropAssetPane.setAsset(this.m_currentBackdrop);
            setBackgroundDecorator(new AssetBackground(this.m_currentBackdrop.background));
            ASwingHelper.prepare(this);
        }
        private function onBackdropRemoveAnimalFromDisplay(_arg1:ZooDialogEvent):void{
            var _local2:TMechanicDataTransfer;
            var _local3:ArrayList;
            var _local4:int;
            var _local5:ZooCell;
            if (((this.m_currSlotMechanic) && (this.m_currStorageMechanic))){
                this.m_currSlotMechanic.emptySlot(_arg1.slotIndex);
                this.m_currStorageMechanic.add(_arg1.animalItemName, 1);
                _local2 = new TMechanicDataTransfer(this.m_currentSelectedEnclosure);
                _local2.addDataTransfer(ZooManager.MECHANIC_SLOTS, ZooManager.MECHANIC_STORAGE, _arg1.animalItemName, {slot:_arg1.slotIndex});
                GameTransactionManager.addTransaction(_local2);
                _local3 = this.m_zooMarket.dataList.getCells();
                _local4 = 0;
                while (_local4 < _local3.size()) {
                    _local5 = (_local3.elementAt(_local4) as ZooCell);
                    if (_local5.animalName == _arg1.animalItemName){
                        _local5.changeCounter(this.m_currStorageMechanic.getCount(_arg1.animalItemName));
                        break;
                    };
                    _local4++;
                };
            };
        }
        private function onTooltipTargetMouseOver(_arg1:MouseEvent):void{
            var _local2:int;
            var _local3:String;
            var _local4:Item;
            if ((_arg1.currentTarget is ZooCell)){
                this.m_toolTip.changeInfo((_arg1.currentTarget as ZooCell));
                if (!this.m_toolTip.visible){
                    this.m_toolTip.visible = true;
                };
            } else {
                if ((_arg1.currentTarget is ImageTab)){
                    this.m_tabToolTip.visible = true;
                    _local2 = this.m_tabs.indexOf(_arg1.currentTarget);
                    this.m_tabToolTip.changeTitle(this.m_tooltipData[this.m_tabs[_local2]]);
                    _local3 = "";
                    _local4 = (this.m_enclosureData[_local2] as Item);
                    if (_local4){
                        if (BuyLogic.isLocked(_local4)){
                            _local3 = ZLoc.t("Dialogs", ("ZooDialog_tabLocked_rollover_" + _local4.name));
                        };
                    };
                    this.m_tabToolTip.changeSubtitle(_local3);
                    this.m_tabToolTip.x = ((this.m_tabs[_local2].x + 2) + (150 - (this.m_tabToolTip.width / 2)));
                    this.m_tabToolTip.y = (this.m_tabs[_local2].y + 240);
                };
            };
        }
        private function onTooltipTargetMouseOut(_arg1:MouseEvent):void{
            if ((_arg1.currentTarget is ZooCell)){
                this.m_toolTip.visible = false;
            } else {
                if ((_arg1.currentTarget is ImageTab)){
                    this.m_tabToolTip.visible = false;
                };
            };
        }
        private function onUnlockEnclosure(_arg1:ZooDialogEvent):void{
            var _local3:Item;
            var _local4:ImageTab;
            var _local5:Boolean;
            var _local2:int;
            while (_local2 < this.m_enclosureData.length) {
                _local3 = this.m_enclosureData[_local2];
                if (_local3.name == _arg1.enclosureName){
                    _local4 = (this.m_tabs[_local2] as ImageTab);
                    if (_local4){
                        _local5 = BuyLogic.isLocked(_local3);
                        _local4.setLocked(_local5);
                    };
                };
                _local2++;
            };
        }

    }
}//package Modules.zoo.ui 

import flash.events.*;
import Engine.Managers.*;
import flash.display.*;
import org.aswing.*;
import org.aswing.geom.*;

class ImageTab extends JPanel {

    public static const TAB_WIDTH:int = 50;
    public static const TAB_HEIGHT:int = 50;

    private var m_outUrl:String;
    private var m_overUrl:String;
    private var m_outAsset:DisplayObject;
    private var m_overAsset:DisplayObject;
    private var m_assetPane:AssetPane;
    private var m_isLocked:Boolean;

    public function ImageTab(_arg1:String=null, _arg2:String=null){
        super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, 1));
        setPreferredSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
        this.m_assetPane = new AssetPane();
        append(this.m_assetPane);
        addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver, false, 0, true);
        addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut, false, 0, true);
        this.m_outUrl = _arg1;
        this.m_overUrl = _arg2;
        if (((!(this.m_outUrl)) || (!(this.m_overUrl)))){
            this.m_outAsset = (new (ZooDialog.assetDict["tab_locked"])() as DisplayObject);
            this.m_overAsset = (new (ZooDialog.assetDict["tab_locked"])() as DisplayObject);
            this.setTabAsset(this.m_outAsset);
        } else {
            LoadingManager.loadFromUrl(this.m_overUrl, {
                priority:LoadingManager.PRIORITY_HIGH,
                completeCallback:this.onOverUrlLoad
            });
            LoadingManager.loadFromUrl(this.m_outUrl, {
                priority:LoadingManager.PRIORITY_HIGH,
                completeCallback:this.onOutUrlLoad
            });
        };
    }
    public function setLocked(_arg1:Boolean):void{
        if (_arg1){
            this.setTabAsset((new (ZooDialog.assetDict["tab_locked"])() as DisplayObject));
            this.m_isLocked = true;
        } else {
            this.m_isLocked = false;
            if (this.m_outAsset){
                this.setTabAsset(this.m_outAsset);
            };
        };
    }
    private function setTabAsset(_arg1:DisplayObject):void{
        if (((!(this.m_isLocked)) && (_arg1))){
            this.m_assetPane.unloadAsset();
            this.m_assetPane.setAsset(_arg1);
        };
    }
    private function onMouseOver(_arg1:MouseEvent):void{
        this.setTabAsset(this.m_overAsset);
    }
    private function onMouseOut(_arg1:MouseEvent):void{
        this.setTabAsset(this.m_outAsset);
    }
    private function onOverUrlLoad(_arg1:Event):void{
        var _local2:LoaderInfo = (_arg1.currentTarget as LoaderInfo);
        this.m_overAsset = (_arg1.target.content as DisplayObject);
    }
    private function onOutUrlLoad(_arg1:Event):void{
        var _local2:LoaderInfo = (_arg1.currentTarget as LoaderInfo);
        this.m_outAsset = (_arg1.target.content as DisplayObject);
        this.setTabAsset(this.m_outAsset);
    }

}
